package com.gopay.scheduler.job;

import com.gopay.common.util.DateUtils;
import com.gopay.remote.cps.ic.InnerCheckRemoteService;
import com.gopay.scheduler.GopayBaseJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description 切日订单定时任务
 * @Author jianghoupeng
 * @Date 2017/1/16 17:32
 *
 * Copyright (c) 2017. www.gopay.com.cn Inc.All rights reserved.
 */
public class IcNextDayOrderJob extends GopayBaseJob {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

   @Resource(name = "InnerCheckRemoteService")
    private InnerCheckRemoteService innerCheckRemoteService;

    @Override
    protected void doJobInternal() {
        logger.info("内部对账切日订单定时任务启动！当前时间为："+ DateUtils.format(new Date()));
        Map param = new HashMap();
        //需要执行内部对账切日订单的对账日 currentTime   为当前时间的前一天
        Calendar calendar = Calendar.getInstance();  //得到日历
        Date dNow = new Date();   //当前时间
        calendar.setTime(dNow);
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1);
        String currentTime = DateUtils.format(calendar.getTime(), "yyyyMMdd");
        param.put("currentTime", currentTime);
        try {
            innerCheckRemoteService.nextDayOrdersProcess(param);
        } catch (Exception e) {
            logger.error("hession调用cps内部对账切日订单接口发生异常!",e);
        }
        logger.info("内部对账切日订单定时任务結束！当前时间为："+ DateUtils.format(new Date()));
    }
}
